﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Li.DingTalk.Model.Robot
{
    /// <summary>
    ///   消息会话处理类  handel
    /// </summary>
    public class RobotHandel
    {

        #region 发送群消息
        /// <summary>
        /// 发送文本消息
        /// </summary>
        /// <param name="textMst"></param>
        /// <param name="path">发送的群 webhook</param>
        /// <returns></returns>
        public static ResultPackage Noaction(textMessage textMst,string path="")
        {
           // var path = "https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8";
            var StrJson = Newtonsoft.Json.JsonConvert.SerializeObject(textMst);
            var noaction = RequestHelper.Post(path, StrJson);
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultPackage>(noaction);
        }

        /// <summary>
        /// ActionCard消息整体跳转ActionCard样式
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="oas">单一Action样式的结构体</param>
        /// <returns></returns>
        public static ResultPackage Noaction(ActionCard oas,string path="")
        {
            var StrJson = Newtonsoft.Json.JsonConvert.SerializeObject(oas);
            var oneaction = RequestHelper.Post(path, StrJson);
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ResultPackage>(oneaction);
        }


        #endregion 

    }


    #region 消息类型体

    /// 文本型的消息类型
    /// </summary>
    public class textMessage
    {
        /// <summary>
        /// 消息类型
        /// </summary>
        public string msgtype
        {
            get;
            set;
        }
        /// <summary>
        ///文本内容
        /// </summary>
        public contentText text
        {
            get;
            set;
        }
        /// <summary>
        /// 可选，微应用agentid。默认在角标处显示企业的名称和图标，如果传入agentid则在角标处显示微应用的名称和图标
        /// </summary>
        public atTarget at
        {
            get;
            set;
        }
    }
    /// <summary>
    /// 消息内容
    /// </summary>
    public class contentText
    {
        public string content
        {
            get;set;
        }
    }
  
    /// <summary>
    /// at对象
    /// </summary>
    public class atTarget
    {
        public string[] atMobiles
        {
            get; set;
        }
        public bool isAtAll
        {
            get;set;
        }
    }

    /// <summary>
    /// markdown类型的消息内容
    /// </summary>
    public class markdownMessage
    {
        /// <summary>
        /// 消息类型
        /// </summary>
        public string msgtype
        {
            get;
            set;
        }
        /// <summary>
        /// 消息内容，支持markdown，语法参考标准markdown语法。图片举例：![alt text](mediaId)
        /// </summary>
        public markdown markdown
        {
            get;
            set;
        }
        /// <summary>
        /// 可选，微应用agentid。默认在角标处显示企业的名称和图标，如果传入agentid则在角标处显示微应用的名称和图标
        /// </summary>
        public atTarget at
        {
            get;
            set;
        }
    }
    /// <summary>
    /// 消息内容
    /// </summary>
    public class markdown
    {
        public string title
        {
            get; set;
        }
        public string text
        {
            get; set;
        }
    }


    /// <summary>
    /// markdown类型的消息内容
    /// </summary>
    public class ActionCard
    {
        /// <summary>
        /// 消息类型
        /// </summary>
        public string msgtype
        {
            get;
            set;
        }
        /// <summary>
        /// 消息内容，支持markdown，语法参考标准markdown语法。图片举例：![alt text](mediaId)
        /// </summary>
        public actionC actionCard
        {
            get;
            set;
        }
       
    }
    /// <summary>
    /// 按钮体
    /// </summary>
    public class actionC
    {
        public string title
        {
            get; set;
        }
        public string text
        {
            get; set;
        }
        /// <summary>
        /// 0-正常发消息者头像,1-隐藏发消息者头像
        /// </summary>
        public string hideAvatar
        {
            get; set;
        }
        /// <summary>
        /// 0-按钮竖直排列，1-按钮横向排列
        /// </summary>
        public string btnOrientation
        {
            get; set;
        }
        /// <summary>
        /// 按钮集合
        /// </summary>
        public List<btns> btns
        {
            get;set;
        }
    }
    /// <summary>
    /// 按钮体
    /// </summary>
    public class btns
    {
        public string title
        {
            get; set;
        }
        public string actionURL
        {
            get; set;
        }
    }
    #endregion


}
